integer attachment = TRUE;
integer relaychannel = -1812221819;
string cmdname;
key victim;
list gMenu=[];
list statesMenu=[0,0,0,0,0,0,0,0];
list gAvatarAllow;
key ToucherID;
integer gMenuLink =1337;
integer gDemon =1338;
integer channel_dialog;
integer listen_id;
integer listen_id2;
integer channel_dialog2=13337;
string msg ="Info Display";
list sideMenu=[" ","Back"," "];
integer gPlugin =1339;
integer gVic =1329;

llRlvSay(string command)
{
	if(attachment==TRUE)
	{
		llOwnerSay("@"+command);
	}
	else
	{
		llSay(relaychannel,cmdname + "," + (string)victim  + "," + "@"+command);
	}
}

MakeRLVState()
{
	if(attachment==TRUE)
	{
		
	}
}

llLRP(integer element_new, integer placeinlist)
{
	statesMenu = llListReplaceList(statesMenu, [element_new], placeinlist, placeinlist);
}

makeMenu()
{
	llRlvSay("getstatus:="+(string)channel_dialog2);
	listen_id2 = llListen( channel_dialog2, "", NULL_KEY, "");
	llSetTimerEvent(45.0);
}

displayMenu()
{
	gMenu=[];
	gMenu+=sideMenu;
	//Than display
	channel_dialog = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) );
	listen_id = llListen( channel_dialog, "", NULL_KEY, "");
	llDialog(ToucherID, msg,gMenu, channel_dialog);
	llSetTimerEvent(45.0);
	
}

default {
    state_entry() 
    {
    	    
    }
    
    listen(integer channel, string name, key id, string message)
    {
    	if(channel == channel_dialog2)
    	{
    		llListenRemove(listen_id2);
			llSetTimerEvent(0.0);
    		integer _i=1;
    		list gParse = llParseString2List(message, ["/"], ["--"]);
    		msg ="Restriction:\n";
    		for(_i;_i<llGetListLength(gParse);_i++)
    		{
    			string _item=llList2String(gParse,_i);
    			msg +=_item+"\n";
    		}
    		displayMenu();
    	}
    	if(channel == channel_dialog)
    	{
	    	llListenRemove(listen_id);
			llSetTimerEvent(0.0);
			if(message=="Back")llMessageLinked(LINK_THIS, gMenuLink, "DV_MAIN_RLV", ToucherID);
    	}	
    }
    
    on_rez(integer on)
    {
    
    }
    
    link_message(integer sender, integer num, string str, key id)
  	{
  		if(num ==gMenuLink)
  		{
  			if(str==llGetScriptName())
  			{
  				llMessageLinked(LINK_THIS, gDemon, llGetScriptName(), NULL_KEY);
  				ToucherID=id;
  				makeMenu();
  			}
  		}

  		if(num ==gDemon)
  		{
  			if(str =="attachment")attachment=TRUE;
  			else if(str =="device")attachment=FALSE;
  			else if(str!=llGetScriptName())
  			{
				llListenRemove(listen_id);
  			}
  		}
  		if(num==gPlugin)
  		{
  			if(str=="ON_REZ")
  			{
  				MakeRLVState();
  			}
  			if(str=="RESET")
  			{
  				
  			}
  		}
  		if(num==gVic)
  		{
  				victim=(key)str;
  				cmdname = (string)llGetKey();
  		}
  	}
}
